package com.solace.selenium.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.solace.selenium.entity.LogTime;
import com.solace.selenium.mapper.LogTimeMapper;
import com.solace.selenium.service.LogTimeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class LogTimeServiceImpl extends ServiceImpl<LogTimeMapper, LogTime> implements LogTimeService {

    @Override
    public void addLogOpsTime() {
        LogTime logTime = new LogTime();
        logTime.setTime(System.currentTimeMillis());
        save(logTime);
    }

    @Override
    public Long getMax(Long currentTime) {
        Long max= this.baseMapper.getMax();
        if (max==null){
            max = currentTime;
        }
        return max;
    }

    @Override
    public void removeMaxTime(Integer number) {
        //统计总条数
        Long count = countLogs();
        //删除多余的条数
        if (count>number){
            this.baseMapper.removeMaxTime();
        }
    }

    @Override
    public Long countLogs() {
        Long count= this.baseMapper.getCount();
        return count;
    }
}
